package org.chenbingkang.aviator;

import com.googlecode.aviator.AviatorEvaluator;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AviatorApplication {
    public static void main(String... args) throws Exception {
        List<String> ls = AviatorEvaluator.importFunctions(AviatorFunc.class);
        long start = System.currentTimeMillis();
        Map<String, Object> accountMap = new HashMap<>();
        accountMap.put("pwd", "d41d8cd98f00b204e9800998ecf8427e");
        Map<String, Object> result = new HashMap<>();
        result.put("account", "yyint");
        Map<String, Object> item = new HashMap<>(545);
        item.put("msgid", "200526145957707011000001");
        item.put("mobile", "0012105603941");

        item.put("send_time", "2020-05-26 14:59:58");
        item.put("rpt_time", "2020-05-26 14:59:59");
        item.put("rpt_state", "0");
        item.put("rpt_sub_state", "DELIVRD");

        item.put("rpt_desc", "短信发送成功");

        result.put("data", Collections.singleton(item));
        result.put("data1", "[{\"msgid\":\"200526145957707011000001\",\"mobile\":\"0012105603941\",\"send_time\":\"2020-05-26 14:59:58\",\"rpt_time\":\"2020-05-26 14:59:59\",\"rpt_state\":\"0\",\"rpt_sub_state\":\"DELIVRD\",\"rpt_desc\":\"短信发送成功\"}]");

        result.put("time", "1590476399638");
        Map<String, Object> env = new HashMap<String, Object>();
        env.put("A", accountMap);
        env.put("R", result);
//            Object o = AviatorEvaluator.execute("AviatorFunc.getMD5(R.account+AviatorFunc.writeValueAsString(R.data)+R.time+A.pwd)", env);
        Object o = AviatorEvaluator.execute("R.account+AviatorFunc.writeValueAsString(R.data)+R.time+A.pwd", env);
        System.out.println(o);

        o = AviatorEvaluator.execute("R.account+R.data1+R.time+A.pwd", env);

        System.out.println(o);


    }
}
